from meiduo_admin.mypakge import *


class SPUGoodsView(ModelViewSet):
    """查询获取SPU表数据"""
    queryset = SPU.objects.all()
    serializer_class = SPUSerializer
    pagination_class = MyPage

class SPUBrandView(ListAPIView):
    """保存SPU表数据之获取品牌信息"""
    queryset = Brand.objects.all()
    serializer_class = SPUBrandSerializer

class SPUCategory1(ListAPIView):
    """保存SPU表数据之获取一级分类信息"""
    queryset = GoodsCategory.objects.filter(parent=None)
    serializer_class = SPUCategorySerializer


    def get_queryset(self):
        """保存SPU表数据之获取二三级分类信息"""
        pk = self.kwargs.get('pk')
        if pk is not None:
            return GoodsCategory.objects.filter(parent=pk)
        return self.queryset.filter(parent=None)
